module DataCollectionManager  

  def self.create_data_collection(youth, type_name)
    @data_collection = DataCollection.new(
      :youth_id => youth.id,
      :target_date => calculate_target_date(type_name, youth.institution_placement_date),
      :data_collection_type_id => DataCollectionType.find_by_name(type_name).id)

    @data_collection.save
  end



  private

  def self.calculate_target_date(type_name, institution_placement_date)
    case type_name
    when DataCollectionType.all_types[:PRE_TREATMENT]
      Date.today.to_time.advance(:weeks => 2)
    when DataCollectionType.all_types[:SCAPI1]
      institution_placement_date.to_time.advance(:days => 90)
    when DataCollectionType.all_types[:FEQ]
      institution_placement_date.to_time.advance(:days => 150)
    when DataCollectionType.all_types[:SCAPI2]
      institution_placement_date.to_time.advance(:days => 180)
    when DataCollectionType.all_types[:SCAPI3]
      institution_placement_date.to_time.advance(:days => 270)
    when DataCollectionType.all_types[:SCAPI4]
      institution_placement_date.to_time.advance(:days => 360)
    when DataCollectionType.all_types[:SIX_MONTHS_FOLLOW_UP]
      institution_placement_date.to_time.advance(:months => 6)
    when DataCollectionType.all_types[:ONE_YEAR_FOLLOW_UP]
      institution_placement_date.to_time.advance(:years => 1)
    when DataCollectionType.all_types[:TWO_YEAR_FOLLOW_UP]
      institution_placement_date.to_time.advance(:years => 2)
    end
  end
  
end
